package month3.day30;

import java.util.Arrays;

public class Zulingonsi {
    //公司名字
    private String name;
    //公司电话
    private String dianhua;
    Car[] car = new Car[100];
    Zulingxinxi[] zulingxinxis = new Zulingxinxi[1000];
    //租赁信息个数
    int xinxishu = 0;
    //记录已有车辆数
    int count = 0;
    //以租赁车辆个数，用以计算可出租车辆数
    int zulingshu = 0;

    public Zulingonsi(String name, String dianhua) {
        this.name = name;
        this.dianhua = dianhua;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDianhua() {
        return dianhua;
    }

    public void setDianhua(String dianhua) {
        this.dianhua = dianhua;
    }

    //判断是否重复车牌
    public boolean panduan(String chepai) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(chepai)) {
                return false;
            }
        }
        return true;
    }
    //采购新车
    public void xinche(Car cars) {
        if(count>=car.length)
            Arrays.copyOf(car,car.length*2);
        car[count] = cars;
        count++;
        System.out.println("采购成功");
    }
    //报废不用的车辆
    public boolean baofei(String chepai) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(chepai)) {
                int j;
                for (j = i; j < count - 1; j++) {
                    car[j] = car[j + 1];
                }
                car[j] = null;
                count--;
                return true;
            }
        }
        return false;
    }
    //返回出租车辆对象
    public Car zuche(String chepai) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(chepai)) {
                if(!car[i].getZuangtai()) {
                    System.out.println("车辆已出租");
                    return null;
                }
                car[i].setZuangtai(false);
                zulingshu++;
                return car[i];
            }
        }
        System.out.println("没有此车辆");
        return null;
    }
    //显示当前没有出租车辆信息
    public void weichuzu(String leixing) {
        System.out.println("当前可出租车辆信息");
        for (int i = 0; i < count; i++) {
            if (!car[i].getZuangtai())
                continue;
            if (leixing.equals("客车") && car[i] instanceof Keche) {
                car[i].show();
            } else if (leixing.equals("轿车") && car[i] instanceof Jiaoche)
                car[i].show();
        }

    }
    //显示当前已出租车辆信息
    public void yichuzu() {
        for (int i = 0; i < count; i++) {
            if (!car[i].getZuangtai())
                    car[i].show();
        }
    }
    //根据车牌还车
    public boolean huanche(String chepai) {
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(chepai)) {
                if(car[i].getZuangtai())
                    return false;
                car[i].setZuangtai(true);
                zulingshu--;
                return true;
            }
        }
        return false;
    }
    //显示所有车辆信息
    public void show() {
        for (int i = 0; i < count; i++) {
            car[i].show();
        }
    }
    //记录租赁人信息
    public void zulingxinxis(String name, String chepai,int day) {
        if(xinxishu>=zulingxinxis.length)
            Arrays.copyOf(zulingxinxis,zulingxinxis.length*2);
        zulingxinxis[xinxishu] = new Zulingxinxi(name, chepai,day);
        xinxishu++;
    }
    //输出租赁人信息
    public void xinxi() {
        for (int i = 0; i < xinxishu; i++) {
            System.out.println(zulingxinxis[i]);
        }
    }


}
